package com.heima.wemedia;

import com.heima.file.service.FileStorageService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * @author mrchen
 * @date 2022/7/4 15:00
 */
@SpringBootTest
public class OssDemo {
    @Autowired
    FileStorageService fileStorageService;

    @Value("${file.oss.prefix}")
    String prefix;

    @Value("${file.oss.web-site}")
    String webSite;

    @Test
    public void uploadPic() throws FileNotFoundException {
                               // 阿里云OSS中目录名称   文件的名称  /2022/07/20220704/mv001.jpg
        FileInputStream fileInputStream = new FileInputStream("C:\\worksoft\\picture\\0005.jpg");
        // 返回值: 文件在OSS中的完整名称
        String store = fileStorageService.store(prefix, "mv001.jpg", fileInputStream);
        System.out.println(webSite + store);
    }

    @Test
    public void deletePic() throws FileNotFoundException {
        fileStorageService.delete("material/2022/7/20220704/mv001.jpg");
    }
}
